package cn.kgc.mushroomdatabaseprovider.controller;

import cn.kgc.mushroomcommon.pojo.Order;
import cn.kgc.mushroomdatabaseprovider.service.OrderService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    OrderService orderService;

    @RequestMapping("/selectOrderAndComm")
    public List<Order> selectOrderAndComm(@RequestParam(value = "ordenum",required = false,defaultValue = "") String ordenum){
         List<Order> orders = orderService.selectOrderAndShopAndShopcomm(ordenum);
         return orders;
    }


    @RequestMapping("/deleteOrder")
    public Map<String,Object> deleteOrder(@RequestParam("id")Integer id){
        Map<String,Object> map = new HashMap<>();
         int i = orderService.deleteOrder(id);
         if(i>0){
             map.put("status","删除成功");
         }else{
             map.put("status","删除失败");
         }
         return map;
    }

    @RequestMapping("/insertOrder")
    public Integer insertOrder(@RequestBody Order order){
        return orderService.insertOrder(order);
    }

}
